package de.ubschmidt.capi;

import java.nio.ByteBuffer;

/**
 * With this message the application acknowledges the receipt of a
 * CONNECT_ACTIVE_IND.
 */
public class ConnectActiveResp
        extends CapiActiveMessage
        implements PlciProperty {

    /** The PLCI. */
    private int _plci;

    /**
     * Create a new CONNECT_ACTIVE_RESP with the specified PLCI.
     *
     * @param plci The PLCI.
     */
    public ConnectActiveResp(final int plci) {
        super(Command.CONNECT_ACTIVE_RESP);
        setPlci(plci);
    }

    /**
     * Create a new CONNECT_ACTIVE_RESP with the PLCI contained in the
     * specified {@code ConnectActiveInd}.
     *
     * @param connectActiveInd The {@code ConnectActiveInd} which is to be
     *                         acknoledged by the new {@code ConnectActiveInd}.
     */
    public ConnectActiveResp(final ConnectActiveInd connectActiveInd) {
        this(connectActiveInd.getPlci());
    }

    /** {@inheritDoc} */
    public int getPlci() {
        return _plci;
    }

    /** {@inheritDoc} */
    public void setPlci(final int plci) {
        _plci = plci;
    }

    /** {@inheritDoc} */
    protected void serializeTo(final ByteBuffer byteBuffer) {
        byteBuffer.putInt(_plci);
    }

    /** {@inheritDoc} */
    @Override
    public String toString() {
        String s = String.format("%s[%s plci=0x%08x]",
                getClass().getSimpleName(),
                super.toString(),
                getPlci());

        return s;
    }
}
